package com.cby.operation.sdk.util

import com.cby.operation.common.encrypt.Md5Utils

/**
 * Description:VerifyUtils
 *
 * @author 陈宝阳
 * @create 2020/8/28 16:56
 */
object VerifyUtils {
    /**
     * 签名原始串：x1!x2!x3!x4@x5 签名最终值：md5('原始串')从第3位起，裁剪24位，如 8d7bcf355fe0720006d9147e4b47a12f
     * 裁剪后为：7bcf355fe0720006d9147e4b
     *
     *
     * 其中各个值为： x1: gameId x2: userId  未登录为0 x3: path    当前路径地址  'game/init' 类似这样 x4: time    当前时间戳
     * x5: key     key值：7AE053C3F115699A   每个版本不一致，sdk更新需重新找后端获取
     *
     *
     * 每个接口新增2个字段： time  时间戳 sign  签名值
     */
    //private static final String VERIFY_KEY = "7AE053C3F115699A"; //1.0.0.0的key
    //private static final String VERIFY_KEY = "4272CFEE4BFBE815";  //1.0.1.0的key
    //private static final String VERIFY_KEY = "24158941381AC265";  //1.0.2.0的key
    private const val VERIFY_KEY = "D75C39CF58303F52" //1.0.3.0的key
    private const val SEPARATE_SYMBOL = "!"
    private const val SEPARATE_AT = "@"
    fun getVerifySign(gameId: String?, userId: String?, path: String?, timeStamp: String?): String {
        val sb = StringBuilder()
        sb.append(gameId)
            .append(SEPARATE_SYMBOL)
            .append(userId)
            .append(SEPARATE_SYMBOL)
            .append(path)
            .append(SEPARATE_SYMBOL)
            .append(timeStamp)
            .append(SEPARATE_AT)
            .append(VERIFY_KEY)
        val originSign = sb.toString()
        val sign: String = Md5Utils.md5(originSign)
        return sign.substring(2, 26)
    }
}